<template>
	<view class="content">
		<view class="login-bg">
			<view class="login-card">
				<view class="login-head" v-model="msg">{{msg}}</view>
				<view class="login-input login-margin-b">
					<input v-model="username" placeholder="手机号或者邮箱" />
				</view>
				<view class="login-input">
					<input type="password" v-model="password" placeholder="请输入密码(8-16位)" />
				</view>
				<view class="login-function">
					<view class="login-forget" @click="go_forget">忘记密码</view>
					<view class="login-register" @click="go_register">快速注册></view>
				</view>
			</view>
		</view>
		<view class="login-btn">
			<button class="landing" type="primary" @click="go_login">登陆</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msg:"请输入账户密码",
				username:"",
				password:"",
				myCount:""
			}
		},
		onLoad() {
			
		},
		methods: {
			go_login:function(){
				uni.request({
					url:"http://"+global.address+":8081/user/login/" + this.username + "/" + this.password,
					method:"GET",
					success: (res) => {
						this.myCount = res.data;
						console.log(res.data)
						this.saveMyCount(this.myCount);
					}
				})
			},
			go_forget(){
				uni.navigateTo({
				    url: '../forget/forget'
				})
			},
			go_register(){
				uni.navigateTo({
					url: '../register/register'
				})
			},
			go_index:function(){
				uni.switchTab({
					url:"../index/index"
				})
			},
			saveMyCount:function(data){
				try{
					if(this.myCount != ""){
						console.log(JSON.stringify(this.myCount));
						uni.setStorageSync("myCount",this.myCount);
						this.msg = "登录成功";
						global.isLogin = true;
						this.go_index();
					}else{
						this.msg = "用户名或密码错误"
						console.log(this.msg)
					}
				}catch(e){
					console.log("保存个人信息失败")
				}
			}
		}
	}
</script>

<style>
	.landing{
		height: 84upx;
		line-height: 84upx;
		border-radius: 44upx;
		font-size: 32upx;
		background: #4CD964;
	}
	.login-btn{
		padding: 10upx 20upx;
		margin-top: 350upx;
	}
	.login-function{
		overflow: auto;
		padding: 20upx 20upx 30upx 20upx;
	}
	.login-forget{
		float: left;
		font-size: 26upx;
		color: #999;
	}
	.login-register{
		color: #666;
		float: right;
		font-size: 26upx;

	}
	.login-input input{
		background: #F2F5F6;
		font-size: 28upx;
		padding: 10upx 25upx;
		height: 62upx;
		line-height: 62upx;
		border-radius: 8upx;
	}
	.login-margin-b{
		margin-bottom: 25upx;
	}
	.login-input{
		padding: 10upx 20upx;
	}
	.login-head{
		font-size: 34upx;
		text-align: center;
		padding: 25upx 10upx 55upx 10upx;
	}
	.login-card{
		background: #0000;
		border-radius: 12upx;
		padding: 10upx 25upx;
		box-shadow: #4CD964;
		position: relative;
		margin-top: 120upx;
	}
	.login-bg {
		height: 260upx;
		padding: 25upx;
		background: #4CD964;
	}
</style>
